home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C Templates / mmCommon.c < prev    next >
Text File  |  1995-01-31  |  69KB  |  2,093 lines

  1. $$Message MM Common, mm:mmCommon$Prototype.name$.c
  2. $$File mm:mmCommon$Prototype.name$.c
  3. /*  $CopyRight$ */
  4. /*  mmCommon$Prototype.name$                         Common */
  5.  
  6. /*
  7.     Name:  mmCommon$Prototype.name$.c
  8.     Function:  Common for the Marksman¬ specific code.
  9.     History: $Date$ Original by $Author$
  10.  
  11. */
  12.  
  13.  
  14. #include "mmCommon$Prototype.name$.h"            /* Common */
  15.  
  16. /* ======================================================= */
  17.  
  18. UserEventHRec    UserEventList;                    /* User Event record list start */
  19. EventRecord        myEvent;                        /* Event record for all events */
  20. Boolean            WNE;                            /* WaitNextEvent trap is available */
  21. short            SleepValue;                        /* Sleep value for Wait on events */
  22. Boolean            doneFlag;                        /* Exit program flag */
  23. TEHandle        theInput;                        /* Used in text edit selections */
  24. RgnHandle        cursorRgn;                        /* Cursor region for WaitNextEvent */
  25. short            ReplyMode;                        /* Reply mode for AppleEvents */
  26.  
  27. Rect            tempRect;                        /* Temporary rect, not for long term use */
  28. Str255            sTemp;                            /* Temporary string, not for long term use */
  29. short            tempChar;                        /* Temporary use character */
  30. long            LTemp;                            /* Temporary use long variable */
  31. short            DType;                            /* Temporary use Type of dialog item */
  32. Handle            DItem;                            /* Temporary use Handle to the dialog item */
  33. ControlHandle    CItem;                            /* Temporary use Control handle */
  34.  
  35. WindowLocRec    theWindowLocRec;
  36.  
  37. Boolean            Doing_MovableModal;                /* For Movable Modal dialogs */
  38. Boolean            HoldOffUserEvents;                /* Flag for holding off UserEvents */
  39. Boolean            InTheForeground;                /* Flag for running in MultiFinder foreground */
  40.  
  41. HasRec            Has;                            /* Gestalt check results */
  42. FileRec            Files;                            /* Reading and writing files */
  43. PrintingRec        Printing;                        /* Printing */
  44.  
  45. RGBColor        Black_ForeColor,White_BackColor;/* Standard colors */
  46.  
  47. ProcessSerialNumber        gSelfPSN;
  48. AEAddressDesc                    gSelfAddress;
  49.  
  50. $$Loop Menus
  51. MenuHandle    Menu_$Menu.name$;                    /* Menu handle, $Menu.FullName$ */
  52. $$EndLoop
  53.  
  54. $$Loop HierMenus
  55. MenuHandle    Menu_$Menu.name$;                    /* Hier Menu handle, $Menu.FullName$ */
  56. $$EndLoop
  57.  
  58. $$Loop Alerts
  59. $Worksheet.name$Rec        Rec_$Worksheet.name$;    /* Record for Alert, "$Worksheet.FullName$" */
  60. $$EndLoop Alerts
  61. $$Loop Dialogs
  62. $Worksheet.name$Rec        Rec_$Worksheet.name$;    /* Record for dialog, "$Worksheet.FullName$" */
  63. $$EndLoop
  64. $$Loop Windows
  65. $Worksheet.name$RecPtr    RecPtr_$Worksheet.name$;    /* Record pointer for window, "$Worksheet.FullName$" */
  66. $Worksheet.name$RecPtr    ListRecPtr_$Worksheet.name$;
  67. Boolean                    MultipleAllowed_$Worksheet.name$;
  68. $$EndLoop
  69.  
  70. #define            LowestWindowIndex            0
  71. #define            HighestWindowIndex            10
  72. WindowPtr        TopMostWindows[12];
  73. WindowPtr        BottomMostWindows[12];
  74.  
  75. #define            lmWindowList                0x000009D6
  76.  
  77. /* Variables used by Select Volume */
  78. short            Last_vRefNum;
  79. long            Last_parID;
  80. Str255            Last_Name;
  81.  
  82. #pragma segment Main
  83.  
  84. static void    VerifyWindowLayers(void);
  85.  
  86. static pascal Boolean mySelectCustomFileFilter(CInfoPBPtr pb,Ptr myDataPtr);
  87.  
  88. static pascal short mySelectDlgFilter(short item,DialogPtr theDialog,Ptr myDataPtr);
  89.  
  90. static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
  91.     ControlHandle *theCItem);
  92.  
  93. /* ======================================================= */
  94. /* ======================================================= */
  95.  
  96. void     InitAppleEvents(void)                            /* Initialize for AppleEvents */
  97. {
  98. OSErr    err;                                        /* Error */
  99. AEEventHandlerUPP        theRoutine;
  100.  
  101.  
  102. theRoutine = NewAEEventHandlerProc(DispatchAppleEvent);
  103. err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,
  104.     theRoutine,kAEOpenApplication,false);
  105. err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  106.     theRoutine,kAEOpenDocuments,false);
  107. err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  108.     theRoutine,kAEPrintDocuments,false);
  109. err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
  110.     theRoutine,kAEQuitApplication,false);
  111.  
  112. //err = AEObjectInit();                                /* Init the AE Object code */
  113.  
  114. gSelfPSN.highLongOfPSN = 0;                        /* Init to the current process ID */
  115. gSelfPSN.lowLongOfPSN = kCurrentProcess;
  116. err = AECreateDesc(typeProcessSerialNumber,(Ptr)&gSelfPSN,sizeof(ProcessSerialNumber),&gSelfAddress);
  117. }
  118.  
  119. /* ======================================================= */
  120.  
  121. /* Routine: VerifyWindowLayers */
  122. /* Purpose: Verify all windows are at the proper layer */
  123.  
  124. static void VerifyWindowLayers(void)
  125. {
  126. short        Index,theLayer;
  127. WindowPeek    theWindowPeek;
  128. long         *theWindowListPtr,theRefCon;
  129. WindowPtr    theWindowPtr,theOutOfOrderWindowPtr;
  130. Boolean        Out_Of_Place;
  131.  
  132.  
  133. Out_Of_Place = true;
  134. while (Out_Of_Place)
  135.     {
  136.     Mk_ClearLayers();                                /* Clear all arrays, we will refill them */
  137.     theOutOfOrderWindowPtr = nil;
  138.     Out_Of_Place = false;
  139.  
  140.     Index = HighestWindowIndex + 1;
  141.     theWindowListPtr = (long *)lmWindowList;        /* Get the window list start */
  142.     theWindowPeek = (WindowPeek)*theWindowListPtr;    /* Get the window list start */
  143.     while ((theWindowPeek != nil) && (!Out_Of_Place))
  144.         {
  145.         if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
  146.             {
  147.             theWindowPtr = (WindowPtr)theWindowPeek;/* Get the window pointer */
  148.  
  149.             theRefCon = GetWRefCon(theWindowPtr);
  150.             theRefCon = theRefCon & 0xFF000000;        /* Mask off, to get the layer */
  151.             theLayer = theRefCon >> 24;                /* Move into lower byte */
  152.             if (theLayer < LowestWindowIndex)        /* Pin at 0 */
  153.                 theLayer = LowestWindowIndex;
  154.             if (theLayer > HighestWindowIndex)        /* Pin at top */
  155.                 theLayer = HighestWindowIndex;
  156.             if (theLayer > Index)
  157.                 {
  158.                 Index = theLayer;
  159.                 Out_Of_Place = true;
  160.                 if (theOutOfOrderWindowPtr != nil)
  161.                     SendBehind(theOutOfOrderWindowPtr,theWindowPtr);
  162.                 }
  163.             else if (theLayer < Index)
  164.                 {
  165.                 Index = theLayer;
  166.                 TopMostWindows[theLayer] = theWindowPtr;
  167.                 BottomMostWindows[theLayer]  = theWindowPtr;
  168.                 }
  169.             else
  170.                 BottomMostWindows[theLayer]  = theWindowPtr;
  171.             theOutOfOrderWindowPtr = theWindowPtr;
  172.             }
  173.         theWindowPeek = theWindowPeek->nextWindow;/* Get the next window */
  174.         }
  175.     }
  176.  
  177. }
  178.  
  179. /* ======================================================= */
  180.  
  181. /* Routine: Mk_BehindWindow */
  182. /* Purpose: Get which window to place us behind */
  183.  
  184. WindowPtr Mk_BehindWindow(short theLayer)
  185. {
  186. short        LayerIndex;
  187. WindowPtr    ReturnWindowPtr;
  188.  
  189.  
  190. ReturnWindowPtr = (WindowPtr)-1;                    /* Default to In front of everyone */
  191.  
  192. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  193.  
  194. LayerIndex = HighestWindowIndex;
  195. while ((LayerIndex > theLayer) && (LayerIndex >= LowestWindowIndex))
  196.     {
  197.     if (BottomMostWindows[LayerIndex] != nil)
  198.         ReturnWindowPtr = BottomMostWindows[LayerIndex];
  199.     LayerIndex = LayerIndex - 1;
  200.     }
  201.  
  202. return(ReturnWindowPtr);
  203. }
  204.  
  205. /* ======================================================= */
  206.  
  207. /* Routine: Mk_RegisterWindow */
  208. /* Purpose: Place layer in RefCon and verify layers */
  209.  
  210. void Mk_RegisterWindow(WindowPtr theWindowPtr,short theLayer)
  211. {
  212. long    theRefCon;
  213. long    theLLayer;
  214.  
  215.  
  216. theRefCon = GetWRefCon(theWindowPtr);                /* Get the window refcon */
  217. theRefCon = theRefCon & 0x00FFFFFF;                    /* Mask off, in case something else is there */
  218. theLLayer = theLayer;                                /* Get the window layer */
  219. theLLayer = theLLayer << 24;                        /* Move into upper byte */
  220. theRefCon = theRefCon | theLLayer;                    /* Mask layer into refcon */
  221. SetWRefCon(theWindowPtr, theRefCon);                /* Set the new refcon */
  222.  
  223. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  224. }
  225.  
  226. /* ======================================================= */
  227.  
  228. /* Routine: Mk_ClearLayers */
  229. /* Purpose: Init our arrays for layered windows */
  230.  
  231. void Mk_ClearLayers(void)
  232. {
  233. short    Index;
  234.  
  235.  
  236. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  237.     {
  238.     TopMostWindows[Index] = nil;
  239.     BottomMostWindows[Index] = nil;
  240.     }
  241. }
  242.  
  243. /* ======================================================= */
  244.  
  245. /* Routine: Mk_HiliteWindow */
  246. /* Purpose: Hilite our layered window */
  247.  
  248. void Mk_HiliteWindow(WindowPtr theWindowPtr)
  249. {
  250. WindowPeek    theWindowPeek;
  251. long         *theWindowListPtr;
  252. WindowPtr    WasHilighted,CkHilighted,BehindWindow;
  253. long        theRefCon;
  254. short        theLayer,theWasLayer;
  255.  
  256.  
  257. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  258.  
  259. theRefCon = GetWRefCon(theWindowPtr);
  260. theRefCon = 0xFF000000 & theRefCon;                    /* Mask for top byte */
  261. theLayer = theRefCon >> 24;                            /* Move into lower byte */
  262. if (theLayer < LowestWindowIndex)                    /* Pin at 0 */
  263.     theLayer = LowestWindowIndex;
  264. if (theLayer > HighestWindowIndex)                    /* Pin at top */
  265.     theLayer = HighestWindowIndex;
  266.  
  267. theWindowListPtr = (long *)lmWindowList;            /* Get the window list start */
  268. theWindowPeek = (WindowPeek)*theWindowListPtr;        /* Get the window list start */
  269. WasHilighted = nil;
  270. while (theWindowPeek != nil)
  271.     {
  272.     if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
  273.         {
  274.         if (theWindowPeek->hilited)
  275.             {
  276.             CkHilighted = (WindowPtr)theWindowPeek;
  277.             theRefCon = GetWRefCon(CkHilighted);
  278.             theRefCon = 0xFF000000 & theRefCon;        /* Mask for top byte */
  279.             theWasLayer = theRefCon >> 24;            /* Move into lower byte */
  280.             if (theWasLayer == theLayer)
  281.                 WasHilighted = CkHilighted;
  282.             }
  283.         }
  284.     theWindowPeek = theWindowPeek->nextWindow;
  285.     }
  286.  
  287. if (theWindowPtr != WasHilighted)
  288.     {
  289.     if (WasHilighted != nil)
  290.         {
  291.         theRefCon = GetWRefCon(WasHilighted);
  292.         theRefCon = 0xFF000000 & theRefCon;            /* Mask for top byte */
  293.         theWasLayer = theRefCon >> 24;                /* Move into lower byte */
  294.         if (theWasLayer < LowestWindowIndex)        /* Pin at 0 */
  295.             theWasLayer = LowestWindowIndex;
  296.         if (theWasLayer > HighestWindowIndex)        /* Pin at top */
  297.             theWasLayer = HighestWindowIndex;
  298.         if (theWasLayer == theLayer)
  299.             {
  300.             HiliteWindow(WasHilighted, false);
  301.             myEvent.message = (long)WasHilighted;
  302.             myEvent.modifiers = 0;
  303.             DoActivate();                            /* Deactivate, do links */
  304.             }
  305.         }
  306.  
  307.     HiliteWindow(theWindowPtr, true);
  308.     myEvent.message = (long)theWindowPtr;
  309.     myEvent.modifiers = 1;
  310.     DoActivate();                                    /* Activate, do links */
  311.  
  312.     BehindWindow = Mk_BehindWindow(theLayer);        /* Move to correct layer on the screen */
  313.     if ((long)BehindWindow == -1L)
  314.         BringToFront(theWindowPtr);
  315.     else
  316.         SendBehind(theWindowPtr, BehindWindow);
  317.  
  318.     TopMostWindows[theLayer] = theWindowPtr;
  319.     }
  320.  
  321. }
  322.  
  323. /* ======================================================= */
  324.  
  325. /* Routine: Mk_DragWindow */
  326. /* Purpose: Drag our layered window */
  327.  
  328. void Mk_DragWindow(WindowPtr theWindowPtr,Point where, Rect bounds)
  329. {
  330. GrafPtr            savePort;
  331. CGrafPtr        WMgrPort;
  332. RgnHandle        hRegion,dragRgn;
  333. WindowPeek        theWindowPeek;
  334. long            result;
  335. short            Horz,Vert;
  336. CWindowPtr        theCWindowPtr;
  337. Rect            portBounds;
  338. PixMapHandle    thePixMapHandle;
  339.  
  340.  
  341. if (WaitMouseUp())
  342.     {
  343.     theWindowPeek = (WindowPeek)theWindowPtr;
  344.     theCWindowPtr = (CWindowPtr)theWindowPtr;
  345.  
  346.     GetPort(&savePort);
  347.     if (Has.ColorQD)
  348.         GetCWMgrPort(&WMgrPort);
  349.     else
  350.         GetWMgrPort((GrafPtr *)&WMgrPort);
  351.     SetPort((GrafPtr)WMgrPort);
  352.     hRegion = GetGrayRgn();
  353.     SetClip(hRegion);
  354.  
  355. #if defined(THINK_C) || defined(THINK_CPLUS) || defined(__SC__)
  356.     ClipAbove(theWindowPeek);
  357. #else
  358.     ClipAbove((WindowRef)theWindowPeek);
  359. #endif
  360.  
  361.     dragRgn = NewRgn();
  362.     CopyRgn(theWindowPeek->strucRgn, dragRgn);
  363.  
  364.     result = DragGrayRgn(dragRgn, where, &bounds, &bounds, 0, nil);
  365.     Horz = (result & 0x0000FFFF);
  366.     Vert = (result >> 16) & 0x0000FFFF;
  367.  
  368.     if ((Vert != 0x8000) && (Horz != 0x8000))
  369.         {
  370.         if ((theCWindowPtr->portVersion & 0xC000) != 0)
  371.             {
  372.             thePixMapHandle = theCWindowPtr->portPixMap;
  373.             portBounds = (*thePixMapHandle)->bounds;
  374.             }
  375.         else
  376.             portBounds = theWindowPtr->portBits.bounds;
  377.  
  378.         Horz = Horz + (theWindowPtr->portRect.left - portBounds.left);
  379.         Vert = Vert + (theWindowPtr->portRect.top - portBounds.top);
  380.  
  381.         MoveWindow(theWindowPtr, Horz, Vert, false);
  382.         }
  383.  
  384.     DisposeRgn(dragRgn);
  385.     SetPort(savePort);
  386.     }
  387.  
  388. }
  389.  
  390. /* ======================================================= */
  391.  
  392. /* Routine: Mk_Is_FrontWindow */
  393. /* Purpose: Get the front window */
  394.  
  395. Boolean Mk_Is_FrontWindow(WindowPtr theWindowPtr)
  396. {
  397. Boolean    IsFront;
  398. short    Index;
  399.  
  400.  
  401. IsFront = false;
  402. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  403.     {
  404.     if (TopMostWindows[Index] == theWindowPtr)
  405.         IsFront = true;
  406.     }
  407.  
  408. return(IsFront);
  409. }
  410.  
  411. /* ======================================================= */
  412.  
  413. /* Routine: Mk_CloseLayeredWindow */
  414. /* Purpose: Close a layered window */
  415.  
  416. void Mk_CloseLayeredWindow(WindowPtr theWindowPtr)
  417. {
  418. short    Index;
  419.  
  420.  
  421. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  422.     {
  423.     if (TopMostWindows[Index] == theWindowPtr)
  424.         TopMostWindows[Index] = nil;
  425.     if (BottomMostWindows[Index] == theWindowPtr)
  426.         BottomMostWindows[Index] = nil;
  427.     }
  428. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  429. }
  430.  
  431. /* ======================================================= */
  432.  
  433. /* Routine: GetPreferences */
  434. /* Purpose: Get the preferences */
  435.  
  436. void GetPreferences(void)
  437. {
  438. short        foundVRefNum,PrefsRefNum,FormatRevision,thePrefsFormatRevision;
  439. long        result,foundDirID,DataSize,count,PrefsRecSize;
  440. OSErr        theError;
  441. Boolean        GotPreferences,HasFindFolder;
  442. Str255        thePrefsFilename;
  443. Handle        PrefsHandle;
  444. FSSpec        PrefsFSSpec;
  445. OSType        PrefCreator,PrefType;
  446. SysEnvRec    theEnv;
  447.  
  448.  
  449. /* Get parameters to use */
  450. U_GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
  451.  
  452. GotPreferences = false;                                /* No prefs yet */
  453. HasFindFolder = false;                                /* No FindFolder routine avail yet */
  454. PrefsRefNum = 0;                                    /* No prefs file yet */
  455.  
  456. if (Has.Gestalt)                                    /* Must have Gestalt */
  457.     {
  458.     theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
  459.     if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))
  460.         HasFindFolder = true;
  461.  
  462.     if (HasFindFolder)                                /* Must have FindFolder */
  463.         {
  464.         theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);/* Get preference folder */
  465.         if (theError == 0)
  466.             {
  467.             theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
  468.             if (theError == fnfErr)                    /* File not found */
  469.                 theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
  470.             theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
  471.             }
  472.         }
  473.     else
  474.         {
  475.         theError = SysEnvirons(1,&theEnv);            /* Get volume environs */
  476.         theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  477.         if (theError == fnfErr)                        /* File not found */
  478.             {
  479.             theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
  480.             theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  481.             }
  482.         }
  483.  
  484.     if (theError == 0)
  485.         {
  486.         theError = GetEOF(PrefsRefNum,&DataSize);    /* See if data in the file */
  487.         if (DataSize > 0)                            /* Must have data in the file to go on */
  488.             {
  489.             count = 2;                                /* Revision number size */
  490.             theError = FSRead(PrefsRefNum,&count,&FormatRevision);/* Get revision number */
  491.             theError = SetFPos(PrefsRefNum,fsFromStart,0);/* Beginning again */
  492.  
  493.             if ((FormatRevision == thePrefsFormatRevision) && (PrefsRecSize > 0))/* Only do if up to date revision */
  494.                 {
  495.                 PrefsHandle = NewHandleClear(PrefsRecSize);/* Get space for the prefs */
  496.                 if (PrefsHandle != nil)                /* Make sure we got our little tiny handle */
  497.                     {
  498.                     HLock(PrefsHandle);                /* Lock this for safety */
  499.                     count = PrefsRecSize;            /* See how much data to read */
  500.                     theError = FSRead(PrefsRefNum,&count,*PrefsHandle);/* Read it on in */
  501.                     if (theError == 0)
  502.                         U_GetPreferences(PrefsHandle);/* Let the user get the prefs */
  503.  
  504.                     GotPreferences = true;            /* Got our preferences */
  505.                     HUnlock(PrefsHandle);            /* OK to unlock now */
  506.                     DisposeHandle(PrefsHandle);        /* All done with this record  */
  507.                     }
  508.                 }
  509.             else
  510.                 U_ReadPrefsPrivate(PrefsRefNum);    /* Let the user read the prefs himself */
  511.             }
  512.         if (PrefsRefNum != 0)                        /* Done with the file , close it */
  513.             theError = FSClose(PrefsRefNum);
  514.         }
  515.     }
  516.  
  517. if (!GotPreferences )                                /* If we did not get prefs , use default values */
  518.     SetPreferences();                                /* Set the default values */
  519.  
  520. }
  521.  
  522. /* ======================================================= */
  523.  
  524. /* Routine: SetPreferences */
  525. /* Purpose: Set new preferences */
  526.  
  527. void SetPreferences(void)
  528. {
  529. Str255        thePrefsFilename;
  530. OSErr        theError;
  531. long        result,foundDirID,count,PrefsRecSize;
  532. short        foundVRefNum,PrefsRefNum,thePrefsFormatRevision;
  533. Handle        PrefsHandle;
  534. Boolean        HasFindFolder;
  535. FSSpec        PrefsFSSpec;
  536. OSType        PrefCreator,PrefType;
  537. SysEnvRec    theEnv;
  538.  
  539.  
  540. /* Get parameters to use */
  541. U_GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
  542. PrefsRefNum = 0;
  543.  
  544. PrefsHandle = NewHandleClear(PrefsRecSize);            /* Allocate the prefs space holder */
  545.  
  546. if (PrefsHandle != nil)
  547.     {
  548.     HLock(PrefsHandle);                                /* Lock for safety */
  549.  
  550.     U_SetPreferences(PrefsHandle);                    /* Let the user set the other pref values */
  551.  
  552.     HasFindFolder = false;
  553.     if (Has.Gestalt)                                /* Must have Gestalt */
  554.         {
  555.         theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
  556.         if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))/* See if FindFolder */
  557.             HasFindFolder = true;
  558.  
  559.         if (HasFindFolder )                            /* Must have FindFolder */
  560.             {
  561.             theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);
  562.             if (theError == 0)
  563.                 {
  564.                 theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
  565.                 if (theError == fnfErr)                /* File not found */
  566.                     theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
  567.                 theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
  568.                 }
  569.             }
  570.         else
  571.             {
  572.             theError = SysEnvirons(1,&theEnv);        /* Get volume environs */
  573.             theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  574.             if (theError == fnfErr)                    /* File not found */
  575.                 {
  576.                 theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
  577.                 theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  578.                 }
  579.             }
  580.  
  581.         if (theError == 0)
  582.             {
  583.             count = PrefsRecSize;
  584.             theError = FSWrite(PrefsRefNum,&count,*PrefsHandle);/* Write new prefs */
  585.             theError = SetEOF(PrefsRefNum,count);    /* Reset EOF */
  586.  
  587.             if (PrefsRefNum != 0)
  588.                 theError = FSClose(PrefsRefNum);    /* Close file */
  589.  
  590.             HUnlock(PrefsHandle);
  591.             DisposeHandle(PrefsHandle);                /* Done with Prefs handle */
  592.             }
  593.         }
  594.     }
  595.  
  596. }
  597.  
  598. /* ======================================================= */
  599.  
  600. void PositionWindow(WindowPtr theWindow,Point  WantLocation,Point DefaultPosition)
  601. {
  602. Boolean        FitsOK;
  603. Rect        WindowRect;
  604. GrafPtr        theDesktopPort;
  605. RgnHandle    theRgn,the2Rgn;
  606.  
  607.  
  608. FitsOK = false;                                        /*Init to not on current screen(s) */
  609. WindowRect = theWindow->portRect;                    /* Save the rect to get the size */
  610. OffsetRect(&WindowRect,-WindowRect.left,-WindowRect.top);    /* Offset to 0,0 */
  611. OffsetRect(&WindowRect,WantLocation.h,WantLocation.v);        /* Offset to wanted location */
  612.  
  613. GetWMgrPort(&theDesktopPort);                        /* Get the screen */
  614.  
  615. theRgn = NewRgn();                                    /* Make temp regions */
  616. the2Rgn = NewRgn();
  617. RectRgn(theRgn,&WindowRect);                        /* First region to our window rectangle on the screen */
  618. SectRgn(theRgn,theDesktopPort->visRgn,the2Rgn);        /* Do the intersection with the screen and window */
  619. if (EqualRgn(theRgn,the2Rgn))                        /* If all of window in the screen area then ... */
  620.     FitsOK = true;                                    /* ...all of the window is on the screen area */
  621. if (EmptyRgn(the2Rgn))
  622.     FitsOK = false;
  623.  
  624. DisposeRgn(theRgn);                                    /* Dispose of temp regions */
  625. DisposeRgn(the2Rgn);
  626. if ((FitsOK) && ((WantLocation.h != 0) || (WantLocation.v != 0)))    /* If all of window in the screen area then ... */
  627.     MoveWindow(theWindow,WantLocation.h,WantLocation.v,false);    /* Move to saved location */
  628. else
  629.     MoveWindow(theWindow,DefaultPosition.h,DefaultPosition.v,false); /* Move to original location */
  630. }
  631.  
  632. /* ======================================================= */
  633.  
  634. /* Routine: PStrCopy */
  635. /* Purpose: Copy Pascal strings */
  636.  
  637. void PStrCopy(Str255 *SourceString, Str255 *DestString)/* Copy Pascal strings */
  638. {
  639.  
  640.  
  641. *DestString[0] = *SourceString[0];                    /* Get the string size */
  642. if (*DestString[0] != 0)                            /* Do if there is anything in the string */
  643.     BlockMove(SourceString,DestString,*DestString[0]+1);
  644. }
  645.  
  646. /* ======================================================= */
  647.  
  648. /* Routine: PStrCat */
  649. /* Purpose: Concat Pascal strings */
  650.  
  651. void PStrCat(Str255 *SourceString, Str255 *DestString)/* Concat Pascal strings */
  652. {
  653. short    OldDestLength,NewDestLength,SizeFromSource;
  654.  
  655.  
  656. OldDestLength = *DestString[0];                        /* Get the string old length */
  657. SizeFromSource = *SourceString[0];                    /* Get the source length */
  658. NewDestLength = OldDestLength + SizeFromSource;        /* Get the string new length */
  659. if (NewDestLength > 255)                            /* Compare to length of the final string */
  660.     {
  661.     NewDestLength = 255;                            /* The string final length */
  662.     SizeFromSource = 255 - OldDestLength;            /* The string final length */
  663.     }
  664.  
  665. *DestString[0] = NewDestLength;                        /* Set the string length */
  666. if (SizeFromSource > 0)                                /* Do if there is anything in the string */
  667.     BlockMove((Ptr)((long)SourceString + 1L),(Ptr)((long)DestString+OldDestLength+1L),SizeFromSource);
  668. }
  669.  
  670. /* ======================================================= */
  671.  
  672. /* Routine: PStrCmp */
  673. /* Purpose: Compare Pascal strings for exact match, case sensitive */
  674.  
  675. Boolean PStrCmp(StringPtr Source1String,StringPtr Source2String)/* Compare Pascal strings */
  676. {
  677. short        theLength,Index;
  678. Boolean        theSame;
  679.  
  680.  
  681. theSame = false;                                    /* Init to different */
  682. theLength = *Source1String++;                        /* Get length of one string */
  683. if (theLength == *Source2String++)                    /* Compare to length of other string, easy and quick check */
  684.     {
  685.     theSame = true;                                    /* Init to same, now we will check each character */
  686.     for (Index=1; Index <= theLength; Index++)        /* Compare to length of other string, easy and quick check */
  687.         {
  688.         if (*Source1String++ != *Source2String++)    /* See if this character is the same */
  689.             theSame = false;                        /* Different */
  690.         }
  691.     }
  692.  
  693. return(theSame);
  694. }
  695.  
  696. /* ======================================================= */
  697.  
  698. /* Routine: GetUserEvent */
  699. /* Purpose: See if any user events are available */
  700.  
  701. void GetUserEvent(UserEventPRec TheUserEvent)
  702. UserEventHRec    NextUserEvent;                        /* The next user event */
  703.  
  704.  
  705. TheUserEvent->ID = UserEvent_None;                    /* Set ID to no events are available */
  706. if (UserEventList != NIL)                            /* Get first entry in the list */
  707.     {
  708.     HLock((Handle)UserEventList);                    /* Lock for safety */
  709.     TheUserEvent->ID = (*UserEventList)->ID;        /* The event ID */
  710.     TheUserEvent->ID2 = (*UserEventList)->ID2;        /* The optional ID */
  711.     TheUserEvent->Data1 = (*UserEventList)->Data1;    /* The optional data */
  712.     TheUserEvent->Data2 = (*UserEventList)->Data2;    /* The optional data */
  713.     TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
  714.     NextUserEvent = (*UserEventList)->Next;            /* The next list */
  715.  
  716.     DisposHandle((Handle)UserEventList);            /* Remove this list item */
  717.     UserEventList = NextUserEvent;                    /* Make the next item the new first item */
  718.     }
  719. }
  720.  
  721. /* ======================================================= */
  722.  
  723. /* Routine: Add_UserEvent */
  724. /* Purpose: Add a user event */
  725.  
  726. void Add_UserEvent(short ID1,short  ID2,long Data1,long Data2,Handle  theHandle)
  727. UserEventHRec    NewUserEvent;                        /* The new user event */
  728. UserEventHRec    theUserEvent;                        /* The user event */
  729.  
  730.  
  731. NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
  732. if (NewUserEvent != NIL)                            /* Only do if we got the new record */
  733.     {
  734.     HLock((Handle)NewUserEvent);                    /* Lock for safety */
  735.     (*NewUserEvent)->ID = ID1;                        /* The event ID */
  736.     (*NewUserEvent)->ID2 = ID2;                        /* The optional ID */
  737.     (*NewUserEvent)->Data1 = Data1;                    /* The optional data */
  738.     (*NewUserEvent)->Data2 = Data2;                    /* The optional data */
  739.     (*NewUserEvent)->theHandle = theHandle;            /* The optional handle */
  740.     (*NewUserEvent)->Next = NIL;                    /* No next item after this one */
  741.  
  742.     if (UserEventList == NIL)                        /* See if anyone is in the list yet */
  743.         UserEventList = NewUserEvent;                /* Make this one the first in the list */
  744.     else
  745.         {
  746.         theUserEvent = UserEventList;                /* Get the first one */
  747.         while ((*theUserEvent)->Next != NIL)        /* Get the next one */
  748.             {
  749.             theUserEvent = (*theUserEvent)->Next;
  750.             }
  751.         (*theUserEvent)->Next = NewUserEvent;        /* Tack on to the end */
  752.         }
  753.     }
  754. }
  755.  
  756. /* ======================================================= */
  757.  
  758. /* Routine: SetNameForPopup */
  759. /* Purpose: Set the title for a popup control */
  760.  
  761. void SetNameForPopup(ControlHandle theControl)
  762. Handle    theHandle;                                    /* The resource handle */
  763. ResType    theType;                                    /* Returned type */
  764. short    theID;                                        /* Returned ID */
  765. short    theMenuID;                                    /* Menu ID */
  766.  
  767.  
  768. theMenuID = GetCtlMax(theControl);                    /* Get the menu ID */
  769. theHandle = Get1Resource('MENU', theMenuID);        /* See if the resource is out there */
  770. if (theHandle != nil)                                /* See if we got the menu */
  771.     GetResInfo(theHandle,&theID,&theType,sTemp);    /* Get the title */
  772. else                                                /* Else no menu here */
  773.     sTemp[0] = 0;                                    /* Get the title */
  774. SetCTitle(theControl,sTemp);                        /* Set the title */
  775. }
  776.  
  777. /* ======================================================= */
  778.  
  779. /* Routine: Make_A_List */
  780. /* Purpose: This is a routine used to make a new list */
  781.  
  782. void Make_A_List(ListHandle *theList,Rect *theListRect,WindowPtr theWindow,short theStringResourceID,
  783.     short theSize,short theFont,Style theStyle,Boolean InDialog)
  784. {
  785. Point    cSize;                                        /* Use to point to proper row */
  786. Handle    theHandle;                                    /* Temp Handle */
  787. Rect    dataBounds;
  788.  
  789.  
  790. TextSize(theSize);                                    /* Set text size */
  791. TextFont(theFont);                                    /* Set text font */
  792. TextFace(theStyle);                                    /* Set text style */
  793.  
  794. tempRect = *theListRect;
  795. tempRect.right = tempRect.right - 15;                /* Go inside the scroll bar area */
  796. SetRect(&dataBounds, 0, 0, 1, 0);                    /* Make the empty list */
  797. cSize.h = theListRect->right - 15 - theListRect->left;/* Get the width of the list */
  798. cSize.v = 0;                                        /* Set the HEIGHT of each list element, based on font selected */
  799.  
  800. *theList = LNew(&tempRect, &dataBounds, cSize, 0, theWindow, TRUE, FALSE, FALSE, TRUE);/* Create the list */
  801. (**theList)->selFlags = lOnlyOne + lNoNilHilite;    /* Set for only one active item at a time */
  802. LDoDraw(FALSE,*theList);                            /* Do not Draw this list structure */
  803.  
  804. theHandle = Get1Resource('STR#',theStringResourceID);/* See if any strings */
  805. if (theHandle != NIL)
  806.     {
  807.     cSize.h = 0;                                    /* Point to the correct column, starts at zero */
  808.     cSize.v = -1;                                    /* Point to the correct row, starts at zero */
  809.     do
  810.         {
  811.         GetIndString(sTemp, theStringResourceID, cSize.v + 2);/* Get the new string */
  812.         if (sTemp[0] > 0)
  813.             Add_List_String(sTemp, *theList, &cSize);/* Add in the new string */
  814.         }
  815.     while (sTemp[0] != 0);                            /* Add all the strings in this resource */
  816.     }
  817.  
  818. LDoDraw(TRUE,*theList);                                /* Draw this list structure */
  819. cSize.h = 0;                                        /* All elements are in column 0e */
  820. cSize.v = 0;                                         /* Select the first list element */
  821. LSetSelect(TRUE, cSize,*theList);
  822.  
  823. if (InDialog)
  824.     TextFont(systemFont);                            /* Back to the system font */
  825. else
  826.     TextFont(applFont);                                /* Back to the application font */
  827. TextSize(12);                                        /* Back to the application size */
  828. TextFace(0);                                        /* Set text style */
  829. }
  830.  
  831. /* ======================================================= */
  832.  
  833. void Play_The_Sound(short ResID)
  834. {
  835. Handle        ResHandle;                                /* The sound resource handle */
  836. short        SndResourceID;                            /* Sound resource ID */
  837. Str255        SndName;                                /* Sound name*/
  838. ResType        theType;                                /* Resource type */
  839. OSErr        MyErr;                                    /* Error flag */
  840.  
  841.  
  842. ResHandle = Get1Resource('snd ', ResID);            /* See if the resource is out there */
  843. if (ResHandle != NIL)                                /* Only do if we got the sound */
  844.     {
  845.     GetResInfo(ResHandle,&SndResourceID,&theType,SndName);
  846. #if defined(THINK_C) || defined(THINK_CPLUS) || defined(__SC__)
  847.     MyErr = SndPlay(NIL,ResHandle,FALSE);
  848. #else
  849.     MyErr = SndPlay(NIL,(SndListHandle)ResHandle,FALSE);
  850. #endif
  851.     ReleaseResource(ResHandle);
  852.     }
  853. }
  854.  
  855. /* ======================================================= */
  856.  
  857. /* Routine: Add_List_String */
  858. /* Purpose: This is a routine used to add strings to an existing list */
  859.  
  860. void Add_List_String(Str255 theString,ListHandle theList,Point *cSize) 
  861. {
  862. short    theRow;                                        /* The Row that we are adding */
  863.  
  864.  
  865. if (theList != NIL)  
  866.     {
  867.     cSize->h = 0;                                    /* Point to the correct column */
  868.     theRow = LAddRow(1, 32000, theList);            /* Add another row at the end of the list */
  869.     cSize->v = theRow;                                /* Point to the row just added */
  870.     LSetCell(&theString[1], theString[0], *cSize,theList);/* Place string in row just created */
  871.     }
  872. }
  873.  
  874. /* ======================================================= */
  875.  
  876. /* Routine: Get_TE_String */
  877. /* Purpose: This is a routine used to get a string from a TE area, limited to 250 characters */
  878.  
  879. void Get_TE_String(TEHandle theTEArea,Str255 *theString)
  880. short Index;                                        /* Use to loop thru the characters */
  881. short TitleLength;                                    /* Number of characters to do */
  882. CharsHandle theCharsHandle;                            /* Used to get global edit text */
  883. Ptr theStringPtr;                                    /* Pointer to the string, byte level */
  884. Ptr theTECharPtr;                                    /* Pointer to the string, byte level */
  885.  
  886.  
  887. theCharsHandle = TEGetText(theTEArea);                /* Get the character handle */
  888. HLock ( ( Handle ) theCharsHandle );                /* Lock it for safety */
  889. theTECharPtr = (Ptr)*theCharsHandle;                /* Get string Ptr */
  890. TitleLength = (*theTEArea)->teLength;                /* Get the number of characters */
  891. *theString[0] = 0;                                    /* Start with an empty string */
  892. if (TitleLength > 0) 
  893.     {
  894.     theStringPtr = (Ptr)((long)theString + (long)1);/* Start of the string data */
  895.     if (TitleLength > 250) 
  896.         TitleLength = 250;
  897.     for (Index = 0; Index < TitleLength; Index++)
  898.         *theStringPtr++ = (char)(*theTECharPtr++);
  899.     *theString[0] = TitleLength;
  900.     }
  901. }
  902.  
  903. /* ======================================================= */
  904.  
  905. /* Routine: Make_TE_Area */
  906. /* Purpose: This is a routine used to create a TE area */
  907.  
  908. void Make_TE_Area(TEHandle *theTEArea,Rect *Position,short theFontSize,
  909.     short theFont,short DefaultStringID)
  910. {
  911. FontInfo    ThisFontInfo;                            /* Use to get the font data */
  912.  
  913.  
  914. TextSize(theFontSize);                                /* Set the size */
  915. TextFont(theFont);                                    /* Set the font */
  916. GetFontInfo(&ThisFontInfo);                            /* Get Ascent height for positioning */
  917.  
  918. tempRect = *Position;                                /* Get the rect */
  919. FrameRect(&tempRect);                                /* Frame this TE area */
  920. InsetRect(&tempRect, 3, 3);                            /* Indent for TE inside of box */
  921. *theTEArea = TENew(&tempRect, &tempRect);            /* Create the TE area */
  922. if (theInput != NIL)                                /* See if there is already a TE area */
  923.     TEDeactivate(theInput);                            /* Yes, so turn it off */
  924.  
  925. theInput = *theTEArea;                                /* Activate the TE area */
  926. GetIndString(sTemp, DefaultStringID, 1);            /* Get the default string */
  927. TESetText(&sTemp[1], sTemp[0], theInput);            /* Place default text in the TE area */
  928. TEActivate(theInput);                                /* Make the TE area active */
  929.  
  930. TextSize(12);                                        /* Restore the size */
  931. TextFont(applFont);                                    /* Restore the font */
  932. }
  933.  
  934. /* ======================================================= */
  935.  
  936. /* Routine: Plot_Sicn */
  937. /* Purpose: This is a routine used to plot an Sicn, small 16x16 icon */
  938.  
  939. void Plot_Sicn(short theSicnID,Rect *Position)
  940. typedef struct SmallIconRec{
  941.     long    theIcon[16];
  942. }SmallIconRec,*SmallIconPtr,**SmallIconHand;
  943.  
  944. SmallIconHand    SmallIcon;                            /* Handle to the SICN resource */
  945. BitMap            theBitMap;                            /* Bitmap for plotting */
  946. Rect            sourceRect, DestRect;                /* Rects for plotting */
  947. GrafPtr            thePort;                            /* Port to draw on to */
  948.  
  949.  
  950. SmallIcon = (SmallIconHand)GetResource('SICN', theSicnID);/* Get the resource */
  951. if (SmallIcon != NIL)                                /* Do if there is a resource */
  952.     {
  953.     SetRect(&sourceRect, 0, 0, 16, 16);                /* Sicns are 16 x 16 */
  954.     DestRect = *Position;                            /* Destination */
  955.     theBitMap.baseAddr = (Ptr)&(*SmallIcon)->theIcon;/* Base address of the bitmap */
  956.     theBitMap.rowBytes = 2;                            /* 2*8 = 16 */
  957.     theBitMap.bounds = sourceRect;                    /* Source rect size */
  958.     GetPort(&thePort);                                /* Get the current port */
  959.     CopyBits(&theBitMap, &thePort->portBits, &sourceRect, &DestRect, srcCopy, NIL);/* Plot it */
  960.     }
  961. }
  962.  
  963. /* ======================================================= */
  964.  
  965. /* Routine: HandleWScrollBar */
  966. /* Purpose: This is a routine used to handle a scrollbar */
  967.  
  968. void HandleWScrollBar (Point myPt,short code,short Increment,short LIncrement,ControlHandle theControl)
  969. {
  970. short    theValue;                                    /* Value of the scrollbar */
  971. long    MaxTick;                                    /* Timer used for repeat scrolling */
  972. Boolean    FirstTime;                                    /* Flag to start scrolling */
  973. short    Start,Stop;
  974.  
  975.  
  976. Start = GetCtlMin(theControl);
  977. Stop = GetCtlMax(theControl);
  978.  
  979. FirstTime = TRUE;                                    /* Do the scroll the first time also */
  980. while (StillDown() || FirstTime)                    /* Do the scroll as long as the button is down */
  981.     {                                                /* Timer used for repeat scrolling */
  982.     FirstTime = FALSE;                                /* Do the scroll the first time only unless auto */
  983.     HiliteControl(theControl, code);                /* Darken the arrow */
  984.     theValue = GetCtlValue(theControl);                /* Get current state */
  985.  
  986.     if (code == inUpButton)                            /* See if in the up/left arrow */
  987.         {
  988.         theValue = theValue - Increment;            /* Subtract the single decrement */
  989.         if (theValue < Start)                        /* Check for boundary conditions */
  990.             theValue = Start;                        /* Bump at the start value */
  991.         }
  992.  
  993.     if (code == inDownButton)                        /* See if in the down/right arrow */
  994.         {
  995.         theValue = theValue + Increment;            /* Add the single increment */
  996.         if (theValue > Stop)                         /* Check for boundary conditions */
  997.             theValue = Stop;                        /* Bump at the stop value */
  998.         }
  999.  
  1000.     if (code == inPageUp)                            /* See if in the up/left grey area */
  1001.         {
  1002.         theValue = theValue - LIncrement;            /* Subtract the page increment */
  1003.         if (theValue < Start)                         /* Check for boundary conditions */
  1004.             theValue = Start;                        /* Bump at the Start value */
  1005.         }
  1006.  
  1007.     if (code == inPageDown)                            /* See if in the down/right grey area */
  1008.         {
  1009.         theValue = theValue + LIncrement;            /* Add the page increment */
  1010.         if (theValue > Stop)                        /* Check for boundary conditions */
  1011.             theValue = Stop;                        /* Bump at the Stop value */
  1012.         }
  1013.  
  1014.     if (code == inThumb)                            /* See if in the drag box area */
  1015.         {
  1016.         code = TrackControl(theControl, myPt, NIL);    /* Let the OS drag it around */
  1017.         theValue = GetCtlValue(theControl);            /* Get current state */
  1018.         }
  1019.  
  1020.     SetCtlValue(theControl, theValue);                /* Set new state */
  1021.  
  1022.     MaxTick = TickCount() + 9;                        /* Time delay for auto-scroll */
  1023.     do                                                /* Start of delay routine */
  1024.         {}
  1025.     while ((Button()) && (TickCount() < MaxTick));    /* Exit when time up or mouse button up */
  1026.     HiliteControl(theControl, 0);                    /* Lighten the arrow */
  1027.     }                                                /* End for StillDown */
  1028. }
  1029.  
  1030. /* ======================================================= */
  1031.  
  1032. /* Routine: mySelectDlgFilter */
  1033. /* Purpose: Filter routine for Select Volume routine */
  1034.  
  1035. static pascal short mySelectDlgFilter (short item,DialogPtr theDialog,Ptr myDataPtr)
  1036. {
  1037. short            theItem;
  1038. short            theWidth;
  1039. short            theNameWidth;
  1040. short            DType;
  1041. Handle            DItem;
  1042. ControlHandle    CItem;
  1043. Str255            sTemp;
  1044. Str255            theName;
  1045. Str255            LastChar;
  1046. Point            cSize;
  1047. Rect            dataBounds;
  1048. Boolean            NamesAreSame;
  1049.  
  1050.  
  1051. theItem = item;
  1052.  
  1053. if (theItem == sfHookNullEvent)
  1054.     {
  1055.     NamesAreSame = PStrCmp((StringPtr)&Last_Name,(StringPtr)&Files.theStdFileReply.sfFile.name);
  1056.     if ((Last_vRefNum != Files.theStdFileReply.sfFile.vRefNum) || (Last_parID != Files.theStdFileReply.sfFile.parID) || (!NamesAreSame))
  1057.         theItem = sfItemFileListUser;
  1058.     }
  1059. else
  1060.     theItem = theItem;
  1061.  
  1062. if (theItem == sfItemFileListUser)
  1063.     {
  1064.     if ((Last_vRefNum != Files.theStdFileReply.sfFile.vRefNum) || (Last_parID != Files.theStdFileReply.sfFile.parID) || (Last_Name != Files.theStdFileReply.sfFile.name))
  1065.         {
  1066.         Last_vRefNum = Files.theStdFileReply.sfFile.vRefNum;
  1067.         Last_parID = Files.theStdFileReply.sfFile.parID;
  1068.         PStrCopy((Str255 *)Files.theStdFileReply.sfFile.name,&Last_Name);
  1069.         GetDItem(theDialog, 10, &DType, &DItem, &tempRect);
  1070.         theWidth = tempRect.right - tempRect.left - 10;
  1071.         PStrCopy((Str255 *)"\pSelect '",&sTemp );
  1072.         theWidth = theWidth - StringWidth(sTemp);
  1073.         PStrCopy((Str255 *)Files.theStdFileReply.sfFile.name,&theName);
  1074.         theNameWidth = StringWidth(theName);
  1075.         if (theNameWidth > theWidth)
  1076.             {
  1077.             LastChar[0] = 1;
  1078.             LastChar[1] = theName[theName[0]];
  1079.             PStrCopy(&theName,&sTemp); 
  1080.             PStrCat((Str255 *)"\p...",&sTemp);
  1081.             PStrCat(&LastChar,&sTemp); 
  1082.             while (StringWidth(sTemp) > (theWidth - 5))
  1083.                 {
  1084.                 theName[0] = theName[0] - 1;
  1085.                 PStrCopy(&theName,&sTemp); 
  1086.                 PStrCat((Str255 *)"\p...",&sTemp);
  1087.                 PStrCat(&LastChar,&sTemp); 
  1088.                 }
  1089.             PStrCat((Str255 *)"\p...",&theName);
  1090.             PStrCat(&LastChar,&theName); 
  1091.             }
  1092.  
  1093.         PStrCopy((Str255 *)"\pSelect '", &sTemp );
  1094.         PStrCat(&theName,&sTemp); 
  1095.         PStrCat((Str255 *)"\p'",&sTemp);
  1096.         CItem = (ControlHandle)DItem;                /* Change dialog handle to control handle */
  1097.         SetCTitle(CItem, sTemp);
  1098.         if (Files.theStdFileReply.sfIsFolder || Files.theStdFileReply.sfIsVolume)
  1099.             HiliteControl(CItem, 0);
  1100.         else
  1101.             HiliteControl(CItem,255);
  1102.         }
  1103.     }
  1104. else if (theItem == 10)
  1105.     theItem = sfItemOpenButton;
  1106.  
  1107. return(theItem);
  1108. }
  1109.  
  1110. /* ======================================================= */
  1111.  
  1112. /* Routine: mySelectCustomFileFilter */
  1113. /* Purpose: Filter file routine for Select Volume routine */
  1114.  
  1115. static pascal Boolean mySelectCustomFileFilter (CInfoPBPtr pb,Ptr myDataPtr)
  1116. {
  1117. Boolean        HideTheItem;
  1118. HFileInfo    *FileRecPtr;
  1119.  
  1120.  
  1121. HideTheItem = true;
  1122. FileRecPtr = (HFileInfo *)pb;
  1123. if ((FileRecPtr->ioFlAttrib & 0x0010) != 0)            /* Doing Folder */
  1124.     HideTheItem = false;
  1125.  
  1126. return(HideTheItem);
  1127. }
  1128.  
  1129. /* ======================================================= */
  1130.  
  1131. /* Routine: Do_The_Select_Volume */
  1132. /* Purpose: This is a routine used to select a user selected folder or volume */
  1133. /* Return TRUE for opened the file OK, else return FALSE */
  1134.  
  1135. Boolean Do_The_Select_Volume (FSSpec *theFile)        /* Select a volume */
  1136. {
  1137. short    Screen_Width;                                /* Size of the current screen */
  1138. short    Screen_Height;                                /* Size of the current screen */
  1139. Point    Where;                                        /* Used for placing the SF dialog */
  1140. Boolean    OpenedOK;                                    /* Flag to return */
  1141. #if defined(powerc) || defined(__powerc)
  1142. FileFilterYDUPP    gMyFileFilterYDUPP;
  1143. DlgHookYDUPP    gMyDlgHookYDUPP;
  1144. #endif
  1145.  
  1146.  
  1147. #if defined(powerc) || defined(__powerc)
  1148. gMyFileFilterYDUPP = NewFileFilterYDProc(mySelectCustomFileFilter);
  1149. gMyDlgHookYDUPP = NewDlgHookYDProc(mySelectDlgFilter);
  1150. #endif
  1151.  
  1152. Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
  1153. Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
  1154.  
  1155. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1156. Where.v = (Screen_Height / 4) - (104 / 2);
  1157. if (Where.v < 60)
  1158.     Where.v = 60;
  1159. InitCursor();
  1160. Files.typeList[0] = 'GRC ';
  1161. Last_vRefNum = -2;
  1162. Last_parID = -2;
  1163. #if defined(powerc) || defined(__powerc)
  1164. CustomGetFile(gMyFileFilterYDUPP,0,Files.typeList,&Files.theStdFileReply,
  1165.     512,Where,gMyDlgHookYDUPP, nil, nil, nil, nil);
  1166. #else
  1167. CustomGetFile((FileFilterYDProcPtr)mySelectCustomFileFilter,0,Files.typeList,&Files.theStdFileReply,
  1168.     512,Where,(DlgHookYDProcPtr)mySelectDlgFilter, nil, nil, nil, nil);
  1169. #endif
  1170.  
  1171. OpenedOK = false;                                    /* Init to did not open the file */
  1172. if (Files.theStdFileReply.sfGood)                    /* Only do if the user did not cancel */
  1173.     {
  1174.     *theFile = Files.theStdFileReply.sfFile;        /* Save the FSSpec */
  1175.     BlockMove((Ptr)&Files.theStdFileReply.sfFile.name,&Files.inputFileName,Files.theStdFileReply.sfFile.name[0]+1);
  1176.     OpenedOK = true;                                /* We selected a folder */
  1177.     }
  1178. else
  1179.     Files.inputFileName[0] = 0;                        /* No name for a folder */
  1180.  
  1181. return(OpenedOK);
  1182. }
  1183.  
  1184. /* ======================================================= */
  1185.  
  1186. /* Routine: Do_The_Open_File */
  1187. /* Purpose: This is a routine used to open a user selected file */
  1188. /* Return TRUE for opened the file OK, else return FALSE */
  1189.  
  1190. Boolean Do_The_Open_File (short NumberOfTypes,short *theVolRefNum,ProcPtr fileFilter,
  1191.     ProcPtr dlgHook)
  1192. {
  1193. short    Screen_Width;                                /* Size of the current screen */
  1194. short    Screen_Height;                                /* Size of the current screen */
  1195. Point    Where;                                        /* Used for placing the SF dialog */
  1196. Boolean    OpenedOK;                                    /* Flag to return */
  1197. OSErr    ErrorCode;
  1198. #if defined(powerc) || defined(__powerc)
  1199. FileFilterUPP    gMyFileFilterUPP;
  1200. DlgHookUPP        gMyDlgHookUPP;
  1201. #endif
  1202.  
  1203.  
  1204. #if defined(powerc) || defined(__powerc)
  1205. gMyFileFilterUPP = NewFileFilterProc(fileFilter);
  1206. gMyDlgHookUPP = NewDlgHookProc(dlgHook);
  1207. #endif
  1208.  
  1209. Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
  1210. Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
  1211.  
  1212. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1213. Where.v = (Screen_Height / 4) - (104 / 2);
  1214. if (Where.v < 60)
  1215.     Where.v = 60;
  1216. InitCursor();
  1217. #if defined(powerc) || defined(__powerc)
  1218. SFGetFile(Where,(StringPtr)"/pNot used",gMyFileFilterUPP,NumberOfTypes,Files.typeList,gMyDlgHookUPP,&Files.Reply);
  1219. #else
  1220. SFGetFile(Where,(StringPtr)"/pNot used",(FileFilterProcPtr)fileFilter,NumberOfTypes,
  1221.     Files.typeList,(DlgHookProcPtr)dlgHook,&Files.Reply);
  1222. #endif
  1223.  
  1224. *theVolRefNum = 0;
  1225. Files.inputRefNum = 0;                                /* We did not open */
  1226.  
  1227. OpenedOK = false;                                    /* Init to did not open the file */
  1228. if (Files.Reply.good)                                /* Only do if the user did not cancel */
  1229.     {
  1230.     BlockMove((Ptr)&Files.Reply.fName,&Files.inputFileName,Files.Reply.fName[0]+1);
  1231.  
  1232.     ErrorCode = SetVol(nil, Files.Reply.vRefNum);    /* Set to this volume for later opens */
  1233.     *theVolRefNum = Files.Reply.vRefNum;
  1234.     OpenedOK = true;                                /* Flag that we are open OK */
  1235.     }
  1236. else
  1237.     Files.inputFileName[0] = 0;                        /* No name for a file */
  1238.  
  1239. return(OpenedOK);
  1240. }
  1241.  
  1242. /* ======================================================= */
  1243.  
  1244. /* Routine: Do_The_Save_File */
  1245. /* Purpose: This is a routine used to save a user selected file */
  1246. /* Return TRUE for opened the file OK, else return FALSE */
  1247.  
  1248. Boolean Do_The_Save_File (OSType creator,OSType fileType,Str255 *Prompt,Str255 *DefaultName,
  1249.     short *theVolRefNum,short *theRefNum,ProcPtr dlgHook)
  1250. {
  1251. short    Screen_Width;                                /* Size of the current screen */
  1252. short    Screen_Height;                                /* Size of the current screen */
  1253. Point    Where;                                        /* Used for placing the SF dialog */
  1254. Boolean    OpenedOK;                                    /* Flag to return */
  1255. OSErr    ErrorCode;
  1256. #if defined(powerc) || defined(__powerc)
  1257. DlgHookUPP        gMyDlgHookUPP;
  1258. #endif
  1259.  
  1260.  
  1261. #if defined(powerc) || defined(__powerc)
  1262. gMyDlgHookUPP = NewDlgHookProc(dlgHook);
  1263. #endif
  1264.  
  1265. Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
  1266. Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
  1267.  
  1268. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1269. Where.v = (Screen_Height / 4) - (104 / 2);
  1270. if (Where.v < 60)
  1271.     Where.v = 60;
  1272. InitCursor();
  1273. #if defined(powerc) || defined(__powerc)
  1274. SFPutFile(Where,(StringPtr)Prompt,(StringPtr)DefaultName,gMyDlgHookUPP,&Files.Reply);
  1275. #else
  1276. SFPutFile(Where,(StringPtr)Prompt,(StringPtr)DefaultName,(DlgHookProcPtr)dlgHook,&Files.Reply);
  1277. #endif
  1278.  
  1279. BlockMove((Ptr)&Files.Reply.fName,&Files.outputFileName,Files.Reply.fName[0]+1);
  1280. *theVolRefNum = Files.Reply.vRefNum;
  1281. *theRefNum = 0;
  1282. Files.outputRefNum = 0;
  1283.  
  1284. OpenedOK = false;                                    /* Init to did not open the file */
  1285. if (Files.Reply.good)                                /* Only do if the user did not cancel */
  1286.     {
  1287.     ErrorCode = FSDelete((StringPtr)&Files.Reply.fName, Files.Reply.vRefNum);/* Delete an older file */
  1288.     ErrorCode = Create((StringPtr)&Files.Reply.fName, Files.Reply.vRefNum, creator, fileType);/* Create the file */
  1289.     ErrorCode = FSOpen((StringPtr)&Files.Reply.fName, Files.Reply.vRefNum, &Files.outputRefNum);/* Try to open the file */
  1290.  
  1291.     if (ErrorCode == 0)                                /* See if we opened it cleanly */
  1292.         {
  1293.         ErrorCode = SetFPos(Files.outputRefNum, fsFromStart, 0);/* Start at file beginning */
  1294.         ErrorCode = SetVol(nil, *theVolRefNum);        /* Set for later saves */
  1295.         *theRefNum = Files.outputRefNum;
  1296.         *theVolRefNum = Files.Reply.vRefNum;
  1297.         OpenedOK = true;                            /* We opened the file OK */
  1298.         }
  1299.     else
  1300.         {
  1301.         ErrorCode = FSClose(Files.outputRefNum);    /* Close it if we can, safety */
  1302.         SysBeep(20);                                /* Just beep at the user, caller can do more */
  1303.         Files.outputRefNum = 0;                        /* Make sure the refnum is inited */
  1304.         }
  1305.     }
  1306.  
  1307. return(OpenedOK);
  1308. }
  1309.  
  1310. /* ======================================================= */
  1311.  
  1312. /* Routine: PageSetup */
  1313. /* Purpose: Do the page setup */
  1314.  
  1315. void PageSetup(void)
  1316. {
  1317. Boolean    Result;                                        /* Result from Setup dialog */
  1318.  
  1319.  
  1320. PrOpen();                                            /* Open the printer driver */
  1321.  
  1322. if (PrError() == noErr)                                /* Only do if no error  */
  1323.     {
  1324.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1325.         {
  1326.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1327.         HLock((Handle)Printing.hPrint);
  1328.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1329.         }
  1330.  
  1331.     Result = PrStlDialog(Printing.hPrint);            /* Setup dialog */
  1332.     PrClose();
  1333.     }
  1334. else
  1335.     SysBeep(1);
  1336. }
  1337.  
  1338. /* ======================================================= */
  1339.  
  1340. /* Routine: PrintJobSetup */
  1341. /* Purpose: Do the job setup */
  1342.  
  1343. void PrintJobSetup(void)
  1344. {
  1345. Boolean    Result;                                        /* Result from Setup dialog */
  1346.  
  1347.  
  1348. PrOpen();                                            /* Open the printer driver */
  1349.  
  1350. if (PrError() == noErr)                                /* Only do if no error  */
  1351.     {
  1352.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1353.         {
  1354.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1355.         HLock((Handle)Printing.hPrint);
  1356.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1357.         }
  1358.  
  1359.     Result = PrJobDialog(Printing.hPrint);            /* Setup dialog */
  1360.     PrClose();
  1361.     }
  1362. else
  1363.     SysBeep(1);
  1364. }
  1365.  
  1366. /* ======================================================= */
  1367.  
  1368. /* Routine: OpenThePrinter */
  1369. /* Purpose: Open the printer and driver for use */
  1370.  
  1371. void OpenThePrinter(Boolean *Cancelled)
  1372. {
  1373.  
  1374.  
  1375. PrOpen();                                            /* Open the printer driver */
  1376.  
  1377. if (PrError() == noErr)                                /* Only do if no error */
  1378.     {
  1379.     Printing.PrinterIsOpen = FALSE;                    /* Whether printer is open or not */
  1380.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1381.         {
  1382.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1383.         HLock((Handle)Printing.hPrint);
  1384.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1385.         }
  1386.  
  1387.     *Cancelled = PrJobDialog(Printing.hPrint);        /* Setup dialog */
  1388.     Printing.CopyCount = (*Printing.hPrint)->prJob.iCopies;    /* Get number of copies to do */
  1389.     *Cancelled = !(*Cancelled);                        /* Inverted logic */
  1390.  
  1391.     Printing.pPrPort = nil;
  1392.  
  1393.     if (*Cancelled == false)                        /* Do if they did not cancel */
  1394.         {
  1395.         Printing.PrinterIsOpen = true;                /* Whether printer is open or not */
  1396.         Printing.PageCount = 1;                        /* For adding in page number */
  1397.         Printing.LineCount = 1;                        /* For printing */
  1398.         Printing.pPrPort = PrOpenDoc(Printing.hPrint, nil, nil);/* Get printing port */
  1399.         }
  1400.     }
  1401. else
  1402.     {
  1403.     SysBeep(1);
  1404.     *Cancelled = TRUE;
  1405.     }
  1406. }
  1407.  
  1408. /* ======================================================= */
  1409.  
  1410. /* Routine: CloseThePrinter */
  1411. /* Purpose: Close the printer */
  1412.  
  1413. void CloseThePrinter(void)
  1414. {
  1415.  
  1416.  
  1417. if (Printing.pPrPort != nil)                        /* Do if we have a port */
  1418.     {
  1419.     PrCloseDoc(Printing.pPrPort);                    /* Clear printing port */
  1420.     Printing.pPrPort = nil;
  1421.     }
  1422.  
  1423. if (Printing.hPrint != nil)                            /* Do if we have a record */
  1424.     {
  1425.     if (((*Printing.hPrint)->prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr))
  1426.         PrPicFile(Printing.hPrint, NIL, NIL, NIL, &Printing.prStatus);/* Spool it */
  1427.     }
  1428. }
  1429.  
  1430. /* ======================================================= */
  1431.  
  1432. /* Routine: SetupTheItem */
  1433. /* Purpose: Setup a dialog or alert item */
  1434.  
  1435. void SetupTheItem(DialogPtr theDialog,short ItemID,Boolean SizeIt,Boolean ShowIt,
  1436.     Boolean EnableIt,Boolean SetTheMax,Rect *thePosition,long ExtraData,short StringID)
  1437. {
  1438. Rect            tempRect;                            /* Temporary rectangle */
  1439. short            DType;                                /* Type of dialog item */
  1440. Handle            DItem;                                /* Handle to the dialog item */
  1441. ControlHandle    CItem;                                /* Control handle */
  1442.  
  1443.  
  1444. GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
  1445. CItem = (ControlHandle)DItem;                        /* Change to control handle */
  1446.  
  1447. if (SizeIt)                                            /* Have to resize all CDEF connected controls */
  1448.     SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  1449. *thePosition = tempRect;                            /* Pass back the zone location and size */
  1450.  
  1451. if (ExtraData != NIL)                                /* See if extra data for a CDEF */
  1452.     (*CItem)->contrlData = (Handle)ExtraData;        /* Send it */
  1453.  
  1454. if (StringID != 0)                                    /* See if a CDEF and needs the title set again*/
  1455.     {
  1456.     GetIndString(sTemp,StringID,1);                    /* Get the string */
  1457.     SetCTitle(CItem,sTemp);                            /* Set the string */
  1458.     }
  1459.  
  1460. if (EnableIt)                                        /* See if enable or disable the zone */
  1461.     HiliteControl (CItem,0);                        /* Enable the zone */
  1462. else
  1463.     HiliteControl (CItem,255);                        /* Dim the zone */
  1464.  
  1465. if (SetTheMax)
  1466.     SetCtlMax(CItem,12345);                            /* Set the flag to the CDEF */
  1467.  
  1468. if (ShowIt)
  1469.     ShowControl(CItem);                                /* Show it to activate it */
  1470. }
  1471.  
  1472. /* ======================================================= */
  1473.  
  1474. /* Routine: CenterOnColorScreen */
  1475. /* Purpose: Center a window onto the deepest color screen */
  1476.  
  1477. void CenterOnColorScreen (WindowPtr theWindow )
  1478. {
  1479. Rect        tempRect,gdRect,temp2Rect;                /* Temporary rectangle */
  1480. GDHandle    theDevice;                                /* Graphic device */
  1481.  
  1482. if ((theWindow != NIL) && (Has.ColorQD))            /* Make sure it is safe to go ahead */
  1483.     {
  1484.     SetRect(&tempRect,-32000,-32000,32000,32000);    /* Look in all directions */
  1485.     theDevice = GetMaxDevice(&tempRect);            /* Get the deepest device */
  1486.  
  1487.     if (theDevice != NIL)                            /* Make sure we got a device */
  1488.         {
  1489.         gdRect = (*theDevice)->gdRect;                /* Get the device rect */
  1490.         temp2Rect = theWindow->portRect;            /* Get the window rect */
  1491.  
  1492.         tempRect.top = gdRect.top + ((gdRect.bottom-gdRect.top)/2) - ((temp2Rect.bottom-temp2Rect.top)/2);
  1493.         tempRect.left = gdRect.left + ((gdRect.right-gdRect.left)/2) - ((temp2Rect.right-temp2Rect.left)/2);
  1494.         MoveWindow(theWindow, tempRect.left, tempRect.top, TRUE);/* Move the window*/
  1495.         SetPort(theWindow);                         /* Prepare to write into our window */
  1496.         }
  1497.     }
  1498. }
  1499.  
  1500. /* ======================================================= */
  1501.  
  1502. /* Routine: GetDeepestColorScreenRect */
  1503. /* Purpose: Get the deepest color screen rect */
  1504.  
  1505. void GetDeepestColorScreenRect (Rect *DeepRect )
  1506. {
  1507. Rect        tempRect;                                /* Temporary rectangle */
  1508. GDHandle    theDevice;                                /* Graphic device */
  1509.  
  1510.  
  1511. *DeepRect = screenRect.bounds;                    /* Default to the main screen */
  1512. theDevice = NIL;                                    /* Default to no device */
  1513. if (Has.ColorQD)                                    /* See if color QuickDraw is around */
  1514.     {
  1515.     SetRect(&tempRect,-32000,-32000,32000,32000);    /* Look in all directions */
  1516.     theDevice = GetMaxDevice(&tempRect);            /* Get the deepest device */
  1517.  
  1518.     if (theDevice != NIL)                            /* Make sure we got a device */
  1519.         *DeepRect = (*theDevice)->gdRect;            /* Get the device rect */
  1520.     }
  1521. }
  1522.  
  1523. /* ======================================================= */
  1524.  
  1525. void HiliteDefaultButton(DialogPtr theDialog,short theItem)
  1526. {
  1527. Rect            tempRect;
  1528. short            DType;                                /* Type of dialog item */
  1529. Handle            DItem;                                /* Handle to the dialog item */
  1530.  
  1531.  
  1532. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1533. PenSize(3, 3);                                        /* Change pen to draw thick default outline */
  1534. InsetRect(&tempRect, -4, -4);                        /* Draw outside the button by 1 pixel */
  1535. FrameRoundRect(&tempRect,16,16);                    /* Draw the outline */
  1536. PenSize(1, 1);                                         /* Restore the pen size to the default value */
  1537. }
  1538.  
  1539. /* ======================================================= */
  1540.  
  1541. void CheckKeysInDialog(DialogPtr theDialog,Boolean *valMyFilter,EventRecord *theEvent,short *itemHit)
  1542. {
  1543. short            chCode;                            /* Key entered */
  1544. char            MyCmdKey;                        /* The command key */
  1545. Boolean            CmdDown;                        /* Flag for command key used */
  1546. Rect            tempRect;                        /* Temporary rectangle */
  1547. short            DType;                            /* Type of dialog item */
  1548. Handle            DItem;                            /* Handle to the dialog item */
  1549. ControlHandle    CItem;                            /* Control handle */
  1550. long            LTemp;
  1551.  
  1552.  
  1553. if (theEvent->what == keyDown)
  1554.     {
  1555.     chCode =  (short)theEvent->message & charCodeMask;/* Get character */
  1556.     MyCmdKey = (char)chCode;                        /* Change to ASCII */
  1557.     CmdDown = ((theEvent->modifiers & cmdKey) != 0);/* Get command key state */
  1558.     if (CmdDown)                                    /* Do if command key was down */
  1559.         {
  1560.         if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
  1561.             {
  1562.             DlgCut(theDialog);
  1563.             *valMyFilter = TRUE;
  1564.             }
  1565.         else if ((MyCmdKey =='c') || (MyCmdKey == 'C')) 
  1566.             {
  1567.             DlgCopy(theDialog);
  1568.             *valMyFilter = TRUE;
  1569.             }
  1570.         else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
  1571.             {
  1572.             DlgPaste(theDialog);
  1573.             *valMyFilter = TRUE;
  1574.             }
  1575.         }
  1576.     else if ((chCode == 13) || (chCode == 3))        /* CR or Enter */
  1577.         {
  1578.         *valMyFilter = TRUE;                            /* Flag we got a hit */
  1579.         *itemHit = 1;                                /* Default for CR */
  1580.         GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
  1581.         if (DType == (ctrlItem + btnCtrl))            /* If a button then ... */
  1582.             {
  1583.             CItem = (ControlHandle)DItem;            /* Make it a controlhandle */
  1584.             HiliteControl(CItem, 10);                /* Hilite it */
  1585.             LTemp = TickCount() + 15;                /* Flash the button for 1/4 second */
  1586.             do
  1587.                 {}
  1588.             while (LTemp > TickCount());
  1589.             HiliteControl(CItem, 0);                /* UnHilite it */
  1590.             }
  1591.         }
  1592.     }
  1593. }
  1594.  
  1595. /* ======================================================= */
  1596.  
  1597. void SetupNormalControl(DialogPtr theDialog,short theItem,Boolean Enabled,short InitialValue)
  1598. {
  1599. Rect            tempRect;                            /* Temporary rectangle variable */
  1600. short            DType;                                /* Type of dialog item */
  1601. Handle            DItem;                                /* Handle to the dialog item */
  1602. ControlHandle    CItem;                                /* Control handle */
  1603.  
  1604.  
  1605. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1606. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1607.  
  1608. if (Enabled)                                        /* See if enable or disable the zone */
  1609.     HiliteControl (CItem,0);                        /* Enable the zone */
  1610. else
  1611.     HiliteControl (CItem,255);                        /* Dim the zone */
  1612.  
  1613. SetCtlValue(CItem,InitialValue);
  1614. }
  1615.  
  1616. /* ======================================================= */
  1617.  
  1618. static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
  1619.     ControlHandle *theCItem)
  1620. {
  1621. Rect            tempRect;                            /* Temporary rectangle variable */
  1622. short            DType;                                /* Type of dialog item */
  1623. Handle            DItem;                                /* Handle to the dialog item */
  1624. ControlHandle    CItem;                                /* Control handle */
  1625. Str255            sTemp;
  1626.  
  1627.  
  1628. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1629. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1630. SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  1631.  
  1632. if (Enabled)                                        /* See if enable or disable the zone */
  1633.     HiliteControl (CItem,0);                        /* Enable the zone */
  1634. else
  1635.     HiliteControl (CItem,255);                        /* Dim the zone */
  1636.  
  1637. SetCtlValue(CItem,0);
  1638.  
  1639. if (MessageResID != 0)
  1640.     {
  1641.     GetIndString(sTemp,MessageResID,1);                /* Get the string */
  1642.     SetCTitle(CItem,sTemp);                            /* Set the string */
  1643.     }
  1644. *theCItem = CItem;
  1645. }
  1646.  
  1647. /* ======================================================= */
  1648.  
  1649. void SetupHotSpot(DialogPtr theDialog,short theItem,Boolean MakeHotSpot,long LineWidth,
  1650.     long ShadowWidth,short MessageResID,Boolean Enabled)
  1651. {
  1652. ControlHandle    CItem;                                /* Control handle */
  1653. long            LTemp;
  1654.  
  1655.  
  1656. BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
  1657.  
  1658. if (MakeHotSpot)
  1659.     LTemp = 0x00FF0000;                                /* Tell the CDEF that it is a HotSpot */
  1660. else
  1661.     LTemp = 0x00000000;                                /* Tell the CDEF that it is a Rectangle */
  1662.  
  1663. if (MessageResID != 0)
  1664.     LTemp = LTemp + 0x01000000;
  1665.  
  1666. LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100);    /* Set the line width */
  1667. LTemp = LTemp + (0x000000FF & ShadowWidth);            /* Set the shadow width */
  1668.  
  1669. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1670.  
  1671. ShowControl(CItem);                                    /* Show it to activate it */
  1672. }
  1673.  
  1674. /* ======================================================= */
  1675.  
  1676. void SetupPlugin(DialogPtr theDialog,short theItem,Boolean Enabled,long NormalID,long HilitedID,
  1677.     short MessageResID)
  1678. {
  1679. ControlHandle    CItem;                                /* Control handle */
  1680. long            LTemp;
  1681.  
  1682.  
  1683. BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
  1684.  
  1685. LTemp = (HilitedID * 0x00010000) + NormalID;    
  1686. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1687.  
  1688. SetCtlMax(CItem,12345);                                /* Set the flag to the CDEF */
  1689.  
  1690. ShowControl(CItem);                                    /* Show it to activate it */
  1691. }
  1692.  
  1693. /* ======================================================= */
  1694.  
  1695. void SetupMinMaxValue(DialogPtr theDialog,short theItem,short min,short max,short value)
  1696. {
  1697. Rect            tempRect;                            /* Temporary rectangle variable */
  1698. short            DType;                                /* Type of dialog item */
  1699. Handle            DItem;                                /* Handle to the dialog item */
  1700. ControlHandle    CItem;                                /* Control handle */
  1701.  
  1702.  
  1703. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1704. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1705. SetCtlMin(CItem,min);                                /* The Min */
  1706. SetCtlMax(CItem,max);                                /* The Max */
  1707. SetCtlValue(CItem,value);                            /* The first selection */
  1708. }
  1709.  
  1710. /* ======================================================= */
  1711.  
  1712. void SetupPopupMenu(DialogPtr theDialog,short theItem,Boolean Enabled,short theMenuID,short value)
  1713. {
  1714. Rect            tempRect;                            /* Temporary rectangle variable */
  1715. short            DType;                                /* Type of dialog item */
  1716. Handle            DItem;                                /* Handle to the dialog item */
  1717. ControlHandle    CItem;                                /* Control handle */
  1718.  
  1719.  
  1720. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1721. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1722. SizeControl(CItem,tempRect.right - tempRect.left, tempRect.bottom - tempRect.top);/* Size it to the item size */
  1723. SetCtlValue(CItem,value);                            /* The first selection */
  1724. SetCtlMax(CItem,theMenuID);                            /* The max value is the menu ID */
  1725.  
  1726. if (Enabled)                                        /* See if enable or disable the zone */
  1727.     HiliteControl (CItem,0);                        /* Enable the zone */
  1728. else
  1729.     HiliteControl (CItem,255);                        /* Dim the zone */
  1730.  
  1731. SetNameForPopup(CItem);                                /* Set the popup title */
  1732. ShowControl(CItem);                                    /* Show it to activate it */
  1733. }
  1734.  
  1735. /* ======================================================= */
  1736.  
  1737. void SetupPalette(DialogPtr theDialog,short theItem,Boolean Enabled,long NumberRows,long NumberCols,
  1738.     long PalPictureID,long HiliteMethod)
  1739. {
  1740. ControlHandle    CItem;                                /* Control handle */
  1741.  
  1742.  
  1743. BasicSetup(theDialog,theItem,Enabled,0,&CItem);
  1744.  
  1745. SetCtlMax(CItem,(NumberRows * 0x00000100) + NumberCols);    /* The max value is the (rows * 0x0100) + columns */
  1746. SetCtlValue(CItem,(1 * 0x0100) + 1 );                /* The current value is the (rows * 0x0100) + columns */
  1747. (*CItem)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
  1748. ShowControl(CItem);                                    /* Show it to activate it */
  1749. }
  1750.  
  1751. /* ======================================================= */
  1752.  
  1753. void SetupIconSicn(DialogPtr theDialog,short theItem,Boolean Enabled,
  1754.     long NormalID,long HilitedID)
  1755. {
  1756. ControlHandle    CItem;                                /* Control handle */
  1757. long            LTemp;
  1758.  
  1759.  
  1760. BasicSetup(theDialog,theItem,Enabled,0,&CItem);
  1761.  
  1762. LTemp = (NormalID * 0x00010000) + HilitedID;    
  1763. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1764.  
  1765. SetCtlMax(CItem,12345);                                /* Set the flag to the CDEF */
  1766.  
  1767. ShowControl(CItem);                                    /* Show it to activate it */
  1768. }
  1769.  
  1770. /* ======================================================= */
  1771.  
  1772. void ClearTheRadio(DialogPtr theDialog,short theItem,short *value)
  1773. {
  1774. Rect            tempRect;                            /* Temporary rectangle variable */
  1775. short            DType;                                /* Type of dialog item */
  1776. Handle            DItem;                                /* Handle to the dialog item */
  1777. ControlHandle    CItem;                                /* Control handle */
  1778.  
  1779.  
  1780. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get which item was pressed */
  1781. CItem = (ControlHandle)DItem;                        /* Change the pointer for getting to the control */
  1782. SetCtlValue(CItem,0);
  1783. *value = 0;                                            /* Set the current Radio value */
  1784. }
  1785.  
  1786. /* ======================================================= */
  1787.  
  1788. void DrawStaticTextBox(short ResID,Rect *theRect,short Justify,short theSize,
  1789.     short theFont,Style theStyle)
  1790. {
  1791. Str255        sTemp;
  1792.  
  1793.  
  1794. TextSize(theSize);                            /* Set text size */
  1795. TextFont(theFont);                            /* Set text font */
  1796. TextFace(theStyle);                            /* Set text style */
  1797. GetIndString(sTemp,ResID,1);                /* Get the string */
  1798. TextBox(&sTemp[1],sTemp[0],theRect,Justify);
  1799.  
  1800. TextFont(applFont);                            /* Back to the application font */
  1801. TextSize(12);                                /* Back to the application size */
  1802. TextFace(0);                                /* Set text style */
  1803. }
  1804.  
  1805. /* ======================================================= */
  1806.  
  1807. void DrawStaticLine(short ResID,short Left,short Top,short theSize,short theFont,Style theStyle)
  1808. {
  1809. Str255        sTemp;
  1810.  
  1811.  
  1812. TextSize(theSize);                            /* Set text size */
  1813. TextFont(theFont);                            /* Set text font */
  1814. TextFace(theStyle);                            /* Set text style */
  1815. GetIndString(sTemp,ResID,1);                /* Get the string */
  1816. MoveTo(Left,Top + theSize - 3);
  1817. DrawString(sTemp);
  1818.  
  1819. TextFont(applFont);                            /* Back to the application font */
  1820. TextSize(12);                                /* Back to the application size */
  1821. TextFace(0);                                /* Set text style */
  1822. }
  1823.  
  1824. /* ======================================================= */
  1825.  
  1826. void DrawTheTEArea(Rect *theTERect,TEHandle theTE,short theSize,short theFont,Style theStyle)
  1827. {
  1828.  
  1829.  
  1830. TextSize(theSize);                            /* Set text size */
  1831. TextFont(theFont);                            /* Set text font */
  1832. TextFace(theStyle);                            /* Set text style */
  1833. FrameRect(theTERect);                        /* Frame this TE area */
  1834. if (theTE != nil)
  1835.     TEUpdate(theTERect,theTE);                /* Update the TE area */
  1836.  
  1837. TextFont(applFont);                            /* Back to the application font */
  1838. TextSize(12);                                /* Back to the application size */
  1839. TextFace(0);                                /* Set text style */
  1840. }
  1841.  
  1842. /* ======================================================= */
  1843.  
  1844. ControlHandle MakeNormalControl(WindowPtr theWindow,short theResID,Boolean Enabled,short InitialValue)
  1845. {
  1846. ControlHandle    theCtrl;
  1847.  
  1848.  
  1849. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new control */
  1850. SetCtlValue(theCtrl,InitialValue);                /* Set the value */
  1851. if (Enabled)
  1852.     HiliteControl(theCtrl,0);                    /* Enable the control */
  1853. else
  1854.     HiliteControl(theCtrl,255);                    /* Disable the control */
  1855.  
  1856. return(theCtrl);
  1857. }
  1858.  
  1859. /* ======================================================= */
  1860.  
  1861. ControlHandle MakeHotSpot(WindowPtr theWindow,short theResID,Boolean MakeHotSpot,long LineWidth,
  1862.     long ShadowWidth,short MessageResID,Boolean Enabled)
  1863. {
  1864. ControlHandle    theCtrl;
  1865. long            LTemp;
  1866. Str255            sTemp;
  1867.  
  1868.  
  1869. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new control */
  1870. HideControl(theCtrl);                            /* Hide till we set all the parameters */
  1871.  
  1872. if (Enabled)
  1873.     HiliteControl(theCtrl,0);                    /* Enable the control */
  1874. else
  1875.     HiliteControl(theCtrl,255);                    /* Disable the control */
  1876.  
  1877. if (MakeHotSpot)
  1878.     LTemp = 0x00FF0000;                            /* Tell the CDEF that it is a HotSpot */
  1879. else
  1880.     LTemp = 0x00000000;                            /* Tell the CDEF that it is a Rectangle */
  1881.  
  1882. LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100);    /* Set the line width */
  1883. LTemp = LTemp + (0x000000FF & ShadowWidth);        /* Set the shadow width */
  1884.  
  1885. if (MessageResID != 0)
  1886.     {
  1887.     LTemp = LTemp + 0x01000000;
  1888.     GetIndString(sTemp,MessageResID,1);            /* Get the string */
  1889.     SetCTitle(theCtrl,sTemp);                    /* Set the string */
  1890.     }
  1891.  
  1892. (*theCtrl)->contrlData = (Handle)LTemp;            /* Send it */
  1893.  
  1894. SetCtlValue(theCtrl,0);
  1895. ShowControl(theCtrl);                            /* Show it to activate it */
  1896.  
  1897. return(theCtrl);
  1898. }
  1899.  
  1900. /* ======================================================= */
  1901.  
  1902. ControlHandle MakeIconSicn(WindowPtr theWindow,short theResID,Boolean Enabled,
  1903.     long NormalID,long HilitedID)
  1904. {
  1905. ControlHandle    theCtrl;
  1906.  
  1907.  
  1908. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  1909. if (Enabled)
  1910.     HiliteControl(theCtrl,0);                    /* Enable the button */
  1911. else
  1912.     HiliteControl(theCtrl,255);                    /* Disable the button */
  1913. (*theCtrl)->contrlData = 
  1914.         (Handle)((NormalID * 0x00010000) + HilitedID);    /* Set the icons to be used */
  1915.  
  1916. return(theCtrl);
  1917. }
  1918.  
  1919. /* ======================================================= */
  1920.  
  1921. ControlHandle MakePlugin(WindowPtr theWindow,short theResID,Boolean Enabled,
  1922.     long NormalID,long HilitedID,short MessageResID,short InitialValue)
  1923. {
  1924. ControlHandle    theCtrl;
  1925. long            LTemp;
  1926. Str255            sTemp;
  1927.  
  1928.  
  1929. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  1930. HideControl(theCtrl);
  1931. if (Enabled)
  1932.     HiliteControl(theCtrl,0);                    /* Enable the button */
  1933. else
  1934.     HiliteControl(theCtrl,255);                    /* Disable the button */
  1935.  
  1936. LTemp = (HilitedID * 0x00010000) + NormalID;    
  1937. (*theCtrl)->contrlData = (Handle)LTemp;            /* Send it */
  1938.  
  1939. SetCtlMax(theCtrl,12345);                        /* Set the flag to the CDEF */
  1940.  
  1941. if (MessageResID != 0)
  1942.     {
  1943.     GetIndString(sTemp,MessageResID,1);            /* Get the string */
  1944.     SetCTitle(theCtrl,sTemp);                    /* Set the string */
  1945.     }
  1946.  
  1947. SetCtlValue(theCtrl,InitialValue);
  1948. ShowControl(theCtrl);                            /* Show it to activate it */
  1949.  
  1950. return(theCtrl);
  1951. }
  1952.  
  1953. /* ======================================================= */
  1954.  
  1955. void MakeMinMaxValue(ControlHandle theControl,short min,short max,short value)
  1956. {
  1957.  
  1958. SetCtlMin(theControl,min);                                /* The Min */
  1959. SetCtlMax(theControl,max);                                /* The Max */
  1960. SetCtlValue(theControl,value);                            /* The first selection */
  1961. }
  1962.  
  1963. /* ======================================================= */
  1964.  
  1965. ControlHandle MakePopupMenu(WindowPtr theWindow,short theResID,Boolean Enabled,
  1966.     short theMenuID,short value)
  1967. {
  1968. ControlHandle    theCtrl;
  1969. long            LTemp;
  1970. Str255            sTemp;
  1971.  
  1972.  
  1973. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  1974. HideControl(theCtrl);
  1975. if (Enabled)
  1976.     HiliteControl(theCtrl,0);                    /* Enable the button */
  1977. else
  1978.     HiliteControl(theCtrl,255);                    /* Disable the button */
  1979.  
  1980. SetCtlMax(theCtrl,theMenuID);                    /* Set the menu for the CDEF */
  1981.  
  1982. SetCtlValue(theCtrl,value);
  1983. SetNameForPopup(theCtrl);                        /* Set the popup title */
  1984. ShowControl(theCtrl);                            /* Show it to activate it */
  1985.  
  1986. return(theCtrl);
  1987. }
  1988.  
  1989. /* ======================================================= */
  1990.  
  1991. void UpdateTheList(RgnHandle theRgn,ListHandle theList,Rect *theRect,short theSize,
  1992.     short theFont,Style theStyle,Boolean InDialog)
  1993. {
  1994. Rect        tempRect;
  1995.  
  1996.  
  1997. TextSize(theSize);                            /* Set text size */
  1998. TextFont(theFont);                            /* Set text font */
  1999. TextFace(theStyle);                            /* Set text style */
  2000.  
  2001. LUpdate(theRgn,theList);                    /* Update this list */
  2002. tempRect = *theRect;                        /* Start with full size */
  2003. InsetRect(&tempRect, -1, -1);                /* Set for framing */
  2004. FrameRect(&tempRect);                        /* Frame it */
  2005.  
  2006. if (InDialog)
  2007.     TextFont(systemFont);                    /* Back to the system font */
  2008. else
  2009.     TextFont(applFont);                        /* Back to the application font */
  2010. TextSize(12);                                /* Back to the application size */
  2011. TextFace(0);                                /* Set text style */
  2012. }
  2013.  
  2014. /* ======================================================= */
  2015.  
  2016. void ClickInTheList(Point myPt,short modifiers,ListHandle theList,short theSize,
  2017.     short theFont,Style theStyle,Boolean InDialog)
  2018. {
  2019. Boolean        DoubleClick;
  2020.  
  2021.  
  2022. TextSize(theSize);                            /* Set text size */
  2023. TextFont(theFont);                            /* Set text font */
  2024. TextFace(theStyle);                            /* Set text style */
  2025.  
  2026. DoubleClick = LClick(myPt,modifiers,theList);
  2027.  
  2028. if (InDialog)
  2029.     TextFont(systemFont);                    /* Back to the system font */
  2030. else
  2031.     TextFont(applFont);                        /* Back to the application font */
  2032. TextSize(12);                                /* Back to the application size */
  2033. TextFace(0);                                /* Set text style */
  2034. }
  2035.  
  2036. /* ======================================================= */
  2037.  
  2038. ControlHandle MakePalette(WindowPtr theWindow,short theResID,Boolean Enabled,long NumberRows,
  2039.     long NumberCols,long PalPictureID,long HiliteMethod)
  2040. {
  2041. ControlHandle    theCtrl;
  2042.  
  2043.  
  2044. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2045. HideControl(theCtrl);
  2046. if (Enabled)
  2047.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2048. else
  2049.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2050.  
  2051. SetCtlMax(theCtrl,(NumberRows * 0x00000100) + NumberCols);    /* The max value is the (rows * 0x0100) + columns */
  2052. SetCtlValue(theCtrl,(1 * 0x0100) + 1 );                /* The current value is the (rows * 0x0100) + columns */
  2053. (*theCtrl)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
  2054.  
  2055. ShowControl(theCtrl);                            /* Show it to activate it */
  2056.  
  2057. return(theCtrl);
  2058. }
  2059.  
  2060. /* ======================================================= */
  2061.  
  2062. void Activate_TE_Area(Boolean InDialog,Point myPt,TEHandle theTE,short textSize,short textFont,Style textStyle)
  2063. {
  2064.  
  2065.  
  2066. TextSize(textSize);                            /* Set text size */
  2067. TextFont(textFont);                            /* Set text font */
  2068. TextFace(textStyle);                        /* Set text style */
  2069. if (theInput != nil)                        /* See if there is already a TE area */
  2070.     TEDeactivate(theInput);                    /* ...Yes, so turn it off */
  2071.  
  2072. theInput = theTE;
  2073. TEActivate(theInput);                        /* Turn it on */
  2074. TEClick(myPt,false,theInput);
  2075. if (InDialog)
  2076.     TextFont(systemFont);                    /* Back to the system font */
  2077. else
  2078.     TextFont(applFont);                        /* Back to the application font */
  2079. TextSize(12);
  2080. TextFace(0);
  2081. }
  2082.  
  2083. /* ======================================================= */
  2084. /* ======================================================= */
  2085. $$CloseFile
  2086.  
  2087.  
  2088.